import Mock from 'mockjs'
import type { Request } from 'express'
export default [
// 用户登录
    {
        method: "post",
        url: "/api/login",
        response: () => ({
        code: 0,
        msg: "ok",
        data: {
            uid: 101,
            username: "passerby",
            token: "asdawewferfeferweweffgrffer",
        },
        }),
    },
//用户列表数据
    {
        method:'get',
        url: '/api/users',
        response: (req:Request) => {
            let page = req.query.page ? Number(req.query.page) : 1
            let size = req.query.size ? Number(req.query.size) : 10
            let total = 50
            const userData = Mock.mock({
                'users|10' : [
                    {
                        'id|+1': (page-1) * size + 1,
                        'userid|+1': 202300 + (page * size + 1),
                        username: '@string("lower",5)',
                        'sex|1': ['1','2'],
                        'age|22-65': 25,
                        region: ['河北','廊坊'],
                        avatar: "@image('50x100','#50B347','#FFF','Mock')",
                        realname: '@cname()',
                        cdate:'@date("yyyy-MM-dd")'
                    }
                ]
            })
            return {
                code: 0,
                msg: 'ok',
                data:{
                    ...userData,
                    total
                }
            }
        }
    },

//添加用户
    {
        method: 'post',
        url: '/api/users',
        response: (req: Request) => {
            return {
                code: 0,
                msg: 'ok',
                data: {
                    id: Date.now(),
                    ...req.body
                }
            }
        }
    }
]